import { BaseEntity } from '@libs/common/entities';
import { enumToObject } from '@libs/common/utils';
import { ApiProperty } from '@nestjs/swagger';
import { Column, Entity, Index } from 'typeorm';

import { OrderResult } from '@/constant.enum';

const StatusComment =
  '订单状态：' +
  Object.keys(enumToObject(OrderResult))
    .map((k) => `${k}: ${enumToObject(OrderResult)[k]}`)
    .join('、');

@Entity('crm_node_market_order')
export class Order extends BaseEntity {
  @ApiProperty({ description: '用户 ID' })
  @Column({ comment: '用户 ID' })
  userId: string;

  @ApiProperty({ description: '用户名称' })
  @Column({ comment: '用户名称' })
  userName: string;

  @Column({ comment: '订单号', unique: true })
  orderNo: string;

  @ApiProperty({ description: StatusComment })
  @Column({ type: 'tinyint', comment: StatusComment })
  status: OrderResult;

  @ApiProperty({ description: '订单总价' })
  @Column('int', { comment: '订单总价' })
  totalPrice: number;

  @ApiProperty({ description: '商品ID' })
  @Column({ comment: '商品ID' })
  productId: string;

  @ApiProperty({ description: '商品名称' })
  @Column({ comment: '商品名称' })
  productName: string;

  @ApiProperty({ description: '商品价格' })
  @Column('int', { comment: '商品价格' })
  productPrice: number;

  @ApiProperty({ description: '商品数量' })
  @Column({ comment: '商品数量' })
  productNumber: number;

  @ApiProperty({ description: '商品图' })
  @Column({ comment: '商品图' })
  productImage?: string;

  @ApiProperty({ description: '流水号' })
  @Column({ comment: '流水号不能为空' })
  deviceTransNo: string;

  @ApiProperty({ description: '货道编号' })
  @Column({ comment: '货道编号不能为空' })
  deviceRoadNo: string;

  @ApiProperty({ description: '货道ID' })
  @Column({ comment: '货道ID不能为空' })
  deviceRoadId: string;
}
